﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Configuration;
using TaskSchedulingSystemForm.Common;

namespace TaskSchedulingSystemForm
{
    static class Program
    {   
        [DllImport("kernel32.dll")]
        static extern bool FreeConsole();
        [DllImport("kernel32.dll")]
        public static extern bool AllocConsole();
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            try
            {
                bool bCreatedNew;
                System.Threading.Mutex mutex = new System.Threading.Mutex(false, Application.ProductName, out bCreatedNew);
                if (!bCreatedNew)
                {
                    MessageBox.Show("应用程序已经启动！");
                    return;
                }
                //网络的设定在logon中会初始化
                if (args == null || args.Length == 0 || (args.Length > 0 && args[0].ToLower() != "nocheckupdate"))
                {
                    var updateSrc = ConfigurationManager.AppSettings["UpdateURL"];
                    var updateInfoFile = "update_c.xml";
                    var logFile = "updater.log";

                    var updater = FSLib.App.SimpleUpdater.Updater.Instance;
                    updater.Context.LogFile = logFile;
                    FSLib.App.SimpleUpdater.Updater.CheckUpdateSimple(updateSrc, updateInfoFile);
                }
                Application.Run(new MainForm());
            }
            catch(Exception ex)
            {
                Mail.SendMail(TSSOP.TSSError, ex.Message+ex.StackTrace);
            }
        }
    }
}
